export function zeroPad(n, num) {
  return (Array(num).join(0) + n).slice(-num)
}

export function getFormatDate(date = null, format = 'Y-m-d H:i:s') {
  if (!date) {
    date = new Date();
  }
  const year = date.getFullYear();
  const month = date.getMonth() + 1;
  const day = date.getDate();

  const hh = date.getHours();       
  const mm = date.getMinutes();      
  const ss = date.getSeconds();
  
  return format.replace('Y', year)
    .replace('m', zeroPad(month, 2))
    .replace('d', zeroPad(day, 2))
    .replace('H', zeroPad(hh, 2))
    .replace('i', zeroPad(mm, 2))
    .replace('s', zeroPad(ss, 2))
}
